package com.teamit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.teamit.entity.ContactNote;
import com.teamit.util.db.DBHelp;
import com.teamit.util.db.RowMapper;

public class ContactNoteDao {
	private DBHelp<ContactNote> db=new DBHelp<ContactNote>();
	public void save(String id,String content,String contact_id,String employee_id){
		String sql="insert into t_contactnote(id,content,contact_id,employee_id) values(?,?,?,?)";
		db.executeSQL(sql,id,content,contact_id,employee_id);
	}
	public List<ContactNote> findById(String contactId){
		String sql="SELECT te.id,te.content,tee.username,te.createtime FROM t_contact AS tc INNER JOIN t_contactnote AS te ON tc.id=? AND tc.id=te.contact_id LEFT JOIN t_employee AS tee ON tee.id=te.employee_id order by createtime desc";
		return db.executeQueryToList(sql, new ContactNoteMapper(), contactId);
		}
	private class ContactNoteMapper implements RowMapper<ContactNote>{

		public ContactNote mapRow(ResultSet rs) throws SQLException {
			ContactNote cn=new ContactNote();
			cn.setId(rs.getString("id"));
			cn.setContent(rs.getString("content"));
			cn.setName(rs.getString("username"));
			cn.setCreatetime(rs.getString("createtime"));
			cn.setTimeStamp(cn.getTime());
			return cn;
		}
		
	}
}
